﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CCWin;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Threading;
using System.Reflection; // 引用这个才能使用Missing字段
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Xml;
using System.Web;
using System.Runtime.InteropServices;

using System.IO;
using System.Net;
using System.Collections;
using System.Xml.Serialization;
namespace weiqijiance
{
    public partial class wendu : CCSkinMain
    {
        public mainform m_mainform;

        public string swendu;
        public string sshidu;
        public string sdaqiya;
        public string hege = "1";
        public wendu()
        {
            InitializeComponent();
            timer1.Enabled = true;
        }
        private delegate void FlushClient();//代理
        private void xianshixinxiWD()
        {
            if (this.text_wendu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxiWD);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_wendu.Text = string.Format(@"{0}", swendu);
            }
        }
        private void xianshixinxiSD()
        {
            if (this.text_wendu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxiSD);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_shidu.Text = string.Format(@"{0}", sshidu);
            }
        }

        private void xianshixinxiDQY()
        {
            if (this.text_wendu.InvokeRequired)//等待异步
            {
                FlushClient fc = new FlushClient(xianshixinxiDQY);
                this.Invoke(fc);//通过代理调用刷新方法
            }
            else
            {
                this.text_daqiya.Text = string.Format(@"{0}", sdaqiya);
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            swendu = string.Format("{0}", m_mainform.objwsddqy.m_fWenDu);
            sshidu = string.Format("{0}", m_mainform.objwsddqy.m_fShiDu);
            sdaqiya = string.Format("{0}", m_mainform.objwsddqy.m_fYaLi);
            xianshixinxiWD();
            xianshixinxiSD();
            xianshixinxiDQY();
        }


        private void skinButton2_Click(object sender, EventArgs e)
        {
            model.尾气自检.dzqxzzijian objxljc = new model.尾气自检.dzqxzzijian();
            objxljc.CheckTempVal = text_wendu.Text;
            objxljc.StdTempVal = text_wendub.Text; 
            objxljc.RateTempVal = "0"; 
            objxljc.RateJudgeTemp = "1";
            objxljc.CheckPressVal = text_daqiya.Text;
            objxljc.StdPressVal = text_daqiyab.Text;
            objxljc.RatePressVal = "0";
            objxljc.RateJudgePress = "1";
            objxljc.CheckHumiVal = text_shidu.Text;
            objxljc.StdHumiVal = text_shidub.Text;
            objxljc.RateHumiVal = "0";
            objxljc.RateJudgeHumi = "1";
            objxljc.nJudegeResult = hege;
            objxljc.dtBeginTime = text_start.Text;
            objxljc.dtEndTime = text_end.Text;
            objxljc.dtCheckDate = DateTime.Now.ToString("yyyy-MM-dd");
            objxljc.jcry = czy.Text.Trim();

            MessageBox.Show(m_mainform.objbass.uploadzj(objxljc));
        }

        private void skinButton4_Click(object sender, EventArgs e)
        {
            text_start.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {

            hege = "1";
            text_end.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

            float wd = (float.Parse(text_wendu.Text) - float.Parse(text_wendub.Text));
            wdwc.Text = wd.ToString("0.00");
            float sd = ((float.Parse(text_shidu.Text) - float.Parse(text_shidub.Text)) / float.Parse(text_shidub.Text)) * 100;
            sdwc.Text = sd.ToString("0.00");
            float dqy = (float.Parse(text_daqiya.Text) - float.Parse(text_daqiyab.Text));
            dqywc.Text = dqy.ToString("0.00");

            if (wd <= (-1) || wd >= (1))
            {
                hege = "0";
            }
            if (sd >= 3 || sd <= (-3))
            {
                hege = "0";
            }
            if (dqy >= 1 || dqy <= (-1))
            {
                hege = "0";
            }
            if (hege.Contains("0"))
                tet_pd.Text = "不合格";
            else
                tet_pd.Text = "合格";
        }

        private void skinButton3_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }

        private void skinButton5_Click(object sender, EventArgs e)
        {
            float fwd = 0, fsd = 0, fyl = 0;
            float.TryParse(text_wendub.Text, out fwd);
            float.TryParse(text_shidub.Text, out fsd);
            float.TryParse(text_daqiyab.Text, out fyl);
            if (m_mainform.objwsddqy.setjianding(fwd, fsd, fyl))
                MessageBox.Show("标定完成");
            else
                MessageBox.Show("标定失败");
        }
    }
}
